package sdufe.lele.mybatisProvider;

import org.apache.ibatis.jdbc.SQL;
import sdufe.lele.model.Userinfo;

/**
 * Created by zhnh9 on 4/15/2017.
 */
public class UpdatesProvider {

    public String userInfoUpdateById(final Userinfo userinfo) {
        return new SQL() {
            {
                UPDATE("userinfo");
                if (userinfo.getUsertele() != null) {
                    SET("userTele = #{usertele}");
                }
                if (userinfo.getUserpassword() != null) {
                    SET("userPassword = #{userpassword}");
                }
                if (userinfo.getUseremail() != null) {
                    SET("userEmail = #{useremail}");
                }
                if (userinfo.getUserage() != null) {
                    SET("userAge = #{userage}");

                }
                WHERE("userId = #{userid}");
            }

        }.toString();
    }

    public String userInfoUpdateByName(final Userinfo userinfo) {
        return new SQL() {
            {
                UPDATE("userinfo");
                if (userinfo.getUsertele() != null) {
                    SET("userTele = #{usertele}");
                }
                if (userinfo.getUserpassword() != null) {
                    SET("userPassword = #{userpassword}");
                }
                if (userinfo.getUseremail() != null) {
                    SET("userEmail = #{useremail}");
                }
                if (userinfo.getUserage() != null) {
                    SET("userAge = #{userage}");

                }
                WHERE("userName = #{username}");

            }
        }.toString();
    }


}
